<%@ page import="java.sql.*" %> 
<%@ page import="java.lang.*" %> 
<%@ page import="java.io.*" %> 
<%
try {
String connectionURL = "jdbc:mysql://webproject2.cse.ust.hk/BookwarmMobile?user=BookwarmMobile&password=bookwarm"; 

Connection connection = null; 

Class.forName("com.mysql.jdbc.Driver").newInstance(); 

connection = DriverManager.getConnection(connectionURL);

if(!connection.isClosed()) {
String newAccountName = null;
String newNickName = null;
String newFirstName  = null;
String newLastName = null;
String newPhoneNumber = null;

newAccountName = request.getParameter("username");
newNickName = request.getParameter("nickname");
newFirstName = request.getParameter("firstname");
newLastName = request.getParameter("lastname");
newPhoneNumber = request.getParameter("phonenumber");

Statement statement0 = null;
ResultSet rs0 = null;
statement0 = connection.createStatement();
int count_record0 = 0;
String query0 = "UPDATE Users SET Users.NickName = '" + newNickName + "' WHERE AccountName = '" + newAccountName + "';";
count_record0 = statement0.executeUpdate(query0, Statement.NO_GENERATED_KEYS);
int count_record1 = 0;
String query1 = "UPDATE Users SET Users.FirstName = '" + newFirstName + "' WHERE AccountName = '" + newAccountName + "';";
count_record1 = statement0.executeUpdate(query1, Statement.NO_GENERATED_KEYS);
int count_record2 = 0;
String query2 = "UPDATE Users SET Users.LastName = UPPER('" + newLastName + "') WHERE AccountName = '" + newAccountName + "';";
count_record2 = statement0.executeUpdate(query2, Statement.NO_GENERATED_KEYS);
int count_record3 = 0;
String query3 = "UPDATE Users SET Users.PhoneNumber = '" + newPhoneNumber + "' WHERE AccountName = '" + newAccountName + "';";
count_record3 = statement0.executeUpdate(query3, Statement.NO_GENERATED_KEYS);
if(count_record0 == 0 || count_record1 == 0 || count_record2 == 0 || count_record3 == 0) {
out.print("update_account_info_failed");

}
else {
out.print("update_account_info_successful");

}

}

connection.close();

}
catch(Exception ex){
out.print(ex);

}
%>